clear all
set type double
set varabbrev on, perm

*** FILL IN MAIN PATH TO RUN CODE ***
global dropbox "..."

global folder "$dropbox/_0_bjps_replication"
global in "$folder/in"
global out "$folder/out"
global proc "$folder/proc"

global graph "$out/graph"
global table "$out/table"
global temp "`c(tmpdir)'"

****************
u "$proc/survey_reg_base.dta", clear

g gig = employment_status2 == 4
g not_working = employment_status1 == 2
replace not_working = 0 if small_biz == 1

label variable gig "Gig Worker Non-SBO"
label variable not_working "Not in Labor Force Non-SBO"

eststo clear

eststo A: reg pid employer_SBO single_SBO not_working gig [pweight = weight]

eststo B: reghdfe pid employer_SBO single_SBO not_working gig  [pweight = weight], absorb(i.age_group i.race_cat i.hispanic_latino i.gender2 i.total_income i.education_level2 i.region) 
 estadd local control = "X"
 
eststo C: reg biden_or employer_SBO single_SBO not_working gig  [pweight = weight]

eststo D: reghdfe biden_or employer_SBO single_SBO not_working gig  [pweight = weight], absorb(i.age_group i.race_cat i.hispanic_latino i.gender2 i.total_income i.education_level2 i.region) 
 estadd local control = "X"
 
esttab A B C D using "$table/GIG_single_employer.tex", replace ///
		cells(b(fmt(%-10.3fc) star) se(par fmt(%-10.3fc))) ///
		stats(control N r2, fmt( 0 0 2)	///
		labels("Controls" "Observations" "R-squared"))	///
		mgroups("PID: Republican" "Trump over Biden",	///		
		pattern(1 0 1 0 )		///		
		prefix(\multicolumn{@span}{c}{) suffix(}) span	) ///
		collabels(none) mlabels(none) label 
 
*****
g start = takeover == 1
g tookover = takeover == 2

eststo clear
eststo A: reg pid start tookover not_working gig [pweight = weight]

eststo B: reghdfe pid start tookover not_working gig [pweight = weight], absorb(i.age_group i.race_cat i.hispanic_latino i.gender2 i.total_income i.education_level2 i.region) 
 estadd local control = "X"
 
eststo C: reg biden_or start tookover not_working gig [pweight = weight]

eststo D: reghdfe biden_or start tookover not_working gig [pweight = weight], absorb(i.age_group i.race_cat i.hispanic_latino i.gender2 i.total_income i.education_level2 i.region) 
 estadd local control = "X"
 
*** ever vs current ***
replace smallbiz_ever = 0 if mi(smallbiz_ever) & small_biz == 1

g current = smallbiz_ever == 0
g previous = smallbiz_ever == 1

eststo a: reg pid current previous not_working gig [pweight = weight]

eststo b: reghdfe pid current previous not_working gig [pweight = weight], absorb(i.age_group i.race_cat i.hispanic_latino i.gender2 i.total_income i.education_level2 i.region) 
 estadd local control = "X"
 
eststo c: reg biden_or current previous not_working gig [pweight = weight]

eststo d: reghdfe biden_or current previous not_working gig [pweight = weight], absorb(i.age_group i.race_cat i.hispanic_latino i.gender2 i.total_income i.education_level2 i.region) 
 estadd local control = "X"

label var start "Started Business"
label var tookover "Took over Business"
label var previous "Former SBO"
label var current "Current SBO"

esttab A B a b C D c d using "$table/GIG_current_takeover.tex", replace ///
		cells(b(fmt(%-10.3fc) star) se(par fmt(%-10.3fc))) ///
		stats(control N r2, fmt( 0 0 2)	///
		labels("Controls" "Observations" "R-squared"))	///
		mgroups("PID: Republican" "Trump over Biden",	///		
		pattern(1 0 0 0 1 0 0 0)		///		
		prefix(\multicolumn{@span}{c}{) suffix(}) span	) ///
		collabels(none) mlabels(none) label 

*********
foreach v of varlist single_SBO employer_SBO{
	g start_`v' = start*`v'
	g tookover_`v' = tookover*`v'
	g current_`v' = current*`v'
	g previous_`v' = previous*`v'
}

eststo clear
eststo A: reg pid start_single_SBO tookover_single_SBO start_employer_SBO tookover_employer_SBO not_working gig [pweight = weight]

eststo B: reghdfe pid start_single_SBO tookover_single_SBO start_employer_SBO tookover_employer_SBO not_working gig [pweight = weight], absorb(i.age_group i.race_cat i.hispanic_latino i.gender2 i.total_income i.education_level2 i.region) 
 estadd local control = "X"
 
eststo C: reg biden_or start_single_SBO tookover_single_SBO start_employer_SBO tookover_employer_SBO not_working gig [pweight = weight]

eststo D: reghdfe biden_or start_single_SBO tookover_single_SBO start_employer_SBO tookover_employer_SBO not_working gig [pweight = weight], absorb(i.age_group i.race_cat i.hispanic_latino i.gender2 i.total_income i.education_level2 i.region) 
 estadd local control = "X"

***********
eststo a: reg pid current_single_SBO previous_single_SBO current_employer_SBO previous_employer_SBO not_working gig [pweight = weight]

eststo b: reghdfe pid current_single_SBO previous_single_SBO current_employer_SBO previous_employer_SBO not_working gig [pweight = weight], absorb(i.age_group i.race_cat i.hispanic_latino i.gender2 i.total_income i.education_level2 i.region) 
 estadd local control = "X"
 
eststo c: reg biden_or current_single_SBO previous_single_SBO current_employer_SBO previous_employer_SBO not_working gig [pweight = weight]

eststo d: reghdfe biden_or current_single_SBO previous_single_SBO current_employer_SBO previous_employer_SBO not_working gig [pweight = weight], absorb(i.age_group i.race_cat i.hispanic_latino i.gender2 i.total_income i.education_level2 i.region) 
 estadd local control = "X"

label var start_employer_SBO "Started X Employer"
label var tookover_employer_SBO "Tookover X Employer"
label var start_single_SBO "Started X Non-Employer"
label var tookover_single_SBO "Tookover X Non-Employer"

label var current_employer_SBO "Current X Employer"
label var previous_employer_SBO "Former X Employer"
label var current_single_SBO "Current X Non-Employer"
label var previous_single_SBO "Former X Non-Employer"

esttab A B a b C D c d using "$table/GIG_current_takeover_employer.tex", replace ///
		cells(b(fmt(%-10.3fc) star) se(par fmt(%-10.3fc))) ///
		stats(control N r2, fmt( 0 0 2)	///
		labels("Controls" "Observations" "R-squared"))	///
		mgroups("PID: Republican" "Trump over Biden",	///		
		pattern(1 0 0 0 1 0 0 0)		///		
		prefix(\multicolumn{@span}{c}{) suffix(}) span	) ///
		collabels(none) mlabels(none) label 

		
eststo clear

eststo B: reghdfe pid single_SBO employer_SBO not_working gig regulation [pweight = weight], absorb(i.age_group i.race_cat i.hispanic_latino i.gender2 i.total_income i.education_level2 i.region) 
 estadd local control = "X"

eststo D: reghdfe biden_or single_SBO employer_SBO not_working gig regulation [pweight = weight], absorb(i.age_group i.race_cat i.hispanic_latino i.gender2 i.total_income i.education_level2 i.region) 
 estadd local control = "X"
 
esttab B D using "$table/GIG_test_reg_tax.tex", replace ///
		cells(b(fmt(%-10.3fc) star) se(par fmt(%-10.3fc))) ///
		stats(control N r2, fmt( 0 0 2)	///
		labels("Controls" "Observations" "R-squared"))	///
		mgroups("PID: Republican" "Trump over Biden",	///		
		pattern(1 1)		///		
		prefix(\multicolumn{@span}{c}{) suffix(}) span	) ///
		collabels(none) mlabels(none) label 		
